1 module core.stdc.stdlib; 2 public import core.stdc.stddef; 3 4 enum EXIT_SUCCESS = 0; 5 enum EXIT_FAILURE = 1; 6 enum RAND_MAX = 0x7fffffff; 7 8 9 alias _compare_fp_t = extern(C) int function(const(void*) a, const(void*) b); 10 11 version(WebAssembly) version = CustomRuntime; 12 version(PSVita) version = CustomRuntime; 13 14 version(CustomRuntime) 15 { 16 private alias nogc_free_t = @nogc nothrow void function(ubyte* ptr, string f = __FILE__, size_t l = __LINE__); 17 private alias nogc_malloc_t = @nogc nothrow ubyte[] function(size_t size, string file, size_t line); 18 private alias nogc_calloc_t = @nogc nothrow ubyte[] function(size_t size, size_t count, string file, size_t line); 19 private alias nogc_realloc_t = @nogc nothrow ubyte[] function(ubyte* ptr, size_t size, string file, size_t line); 20 21 @nogc nothrow 22 { 23 void free(void* ptr, string f = __FILE__, size_t l = __LINE__) 24 { 25 static import rt.hooks; 26 auto nogc_free = cast(nogc_free_t)&rt.hooks.free; 27 nogc_free(cast(ubyte*)ptr, f, l); 28 } 29 void* malloc(size_t size, string file = __FILE__, size_t line = __LINE__) 30 { 31 static import rt.hooks; 32 auto nogc_malloc = cast(nogc_malloc_t)&rt.hooks.malloc; 33 return cast(void*)nogc_malloc(size, file, line).ptr; 34 } 35 void* calloc(size_t count, size_t size, string file = __FILE__, size_t line = __LINE__) 36 { 37 static import rt.hooks; 38 auto nogc_calloc = cast(nogc_calloc_t)&rt.hooks.calloc; 39 return cast(void*)nogc_calloc(count, size, file, line).ptr; 40 } 41 void* realloc(void* ptr, size_t size, string file = __FILE__, size_t line = __LINE__) 42 { 43 static import rt.hooks; 44 auto nogc_realloc = cast(nogc_realloc_t)&rt.hooks.realloc; 45 return cast(void*)nogc_realloc(cast(ubyte*)ptr, size, file, line).ptr; 46 } 47 } 48 void abort(){assert(false, "Aborted");} 49 } 50 else 51 { 52 extern(C) @nogc extern nothrow: 53 void free(void* ptr); 54 void* malloc(size_t size); 55 void* calloc(size_t count, size_t size); 56 void* realloc(void* ptr, size_t size); 57 } 58 version(WebAssembly) 59 { 60 void qsort(void* base, size_t nmemb, size_t size, _compare_fp_t compar){assert(false, "No sort implemented");} 61 void exit(int exitCode){assert(false, "Exit with code unknown");} 62 } 63 else 64 { 65 extern(C) @nogc extern nothrow: 66 void* memmove(void* str1, const(void)* str2, size_t n); 67 void exit(int exitCode); 68 void qsort(void *base, size_t nitems, size_t size, int function (void *, void*) compare); 69 int abs(int a){return a > 0 ? a : -a;} 70 71 @trusted 72 { 73 /// These two were added to Bionic in Lollipop. 74 int rand(); 75 /// 76 void srand(uint seed); 77 } 78 } 79